package com.lineage.william;

import com.lineage.DatabaseFactory;
import com.lineage.server.datatables.ItemTable;
import com.lineage.server.datatables.RecordTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

public class Ezpay_bz {
  public static void getItem(L1PcInstance pc, int count) {
    Connection conn = null;
    try {
      conn = DatabaseFactory.get().getConnection();
      Statement stat = conn.createStatement();
      ResultSet rs = stat.executeQuery("SELECT * FROM ezpay_赞助比值");
      ArrayList<?> arraylist = null;
      if (rs != null)
        while (rs.next()) {
          int itemid = rs.getInt("itemid");
          int min_money = rs.getInt("min_money");
          int max_money = rs.getInt("max_money");
          double itemcountez = rs.getDouble("bz");
          if (count >= min_money && count <= max_money) {
            count = (int)(count * itemcountez);
            pc.getInventory().storeItem(itemid, count);
            L1ItemInstance item = ItemTable.get().createItem(itemid);
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fW获得赞助获得" + item.getName() + ":(" + count + ")"));
            RecordTable.get().recordeSponsor(pc.getName(), count, 0, pc.getIp());
          } 
        }  
      if (conn != null && !conn.isClosed())
        conn.close(); 
    } catch (Exception exception) {}
  }
}
